package com.zlsy.thread.joinlearing;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 * @author zhouliang
 * @date 2020/3/7 19:09
 */
@Slf4j
public class JoinPrinciple {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    TimeUnit.SECONDS.sleep(3);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + "运行完毕");
            }
        });
        //子线程启动
        thread.start();
        System.out.println("开始等待子线程运行完毕。");
//        thread.join();
        //下面的三行代码 等价于 thread.join()
        synchronized (thread) {
            thread.wait();
        }
        System.out.println("所有的子线程运行完毕。");
    }
}
